home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / protect-your-privacy / p.g.p. / pgpamiga / contrib / ced / signpgp.ced < prev   
Text File  |  1996-02-26  |  7KB  |  238 lines

  1. /********************************************************************/
  2. /*                                                                  */
  3. /*  SignPGP.ced - ARexx macro for use with Cygnus Editor and PGP    */
  4. /*                                                                  */
  5. /*  Mark a block of text you want to be signed using PGP, then run  */
  6. /*  this macro. If no block was marked, you may choose to use whole */
  7. /*  file instead. This macro was tested to work with CED 3.5, but   */
  8. /*  should work also with lower versions. It also takes advantage   */
  9. /*  of some PGP non-standard options avaliable in official Amiga    */
  10. /*  port by Peter Simons, but should work also with other versions, */
  11. /*  like the PGP 2.6ui, or plain 2.3a.                              */
  12. /*                                                                  */
  13. /*  This code is in Public Domain under GNU General Public License  */
  14. /*                                                                  */
  15. /*  author: Janusz A. Urbanowicz <alex@vm.cc.uni.torun.pl>          */
  16. /*                                                                  */
  17. /*  See CEDPGP.guide for more info                                  */
  18. /*                                                                  */
  19. /********************************************************************/
  20.  
  21. /*
  22.  *                $VER: SignPGP.ced 1.7 (30.10.1994)
  23.  */
  24.  
  25. Trace Off
  26.  
  27. Options Results
  28.  
  29. lf = '0A'X
  30. tempfile = 'T:ced$pgp.tmp'
  31. scrname = 'CygnusEdScreen'
  32. scrnum = 1
  33. portname = 'rexx_ced'
  34. portnum = 0
  35.  
  36. pgpt = 0 /* pgp 'type' 0 = 2.3a, 1 = 2.3a.?, 2 = 2.6<ui> */
  37.  
  38. cmdn = '-sat ' /* command for NORMAL PGP */
  39. cmdf = '<'||tempfile||' -fast -o '||tempfile||'.asc' /* command for Peter's patchlevel 3,4 and 5 versions */
  40. scratch = 0
  41.  
  42. /*                            main ()                          */
  43.  
  44. status portnumber
  45. portnum = result
  46. if (portnum ~= 0)&(portnum ~== 'RESULT') Then
  47. Do
  48.  scrnum = scrnum + portnum
  49.  portname = portname||portnum
  50. End
  51.  
  52. scrname = scrname||scrnum
  53.  
  54.  
  55. Call Close 'STDOUT'             /* Thanx for that goes to Rick Younie*/
  56. Call Close 'STDIN'
  57. Call Open 'STDOUT','CON:16/24/620/130/PGPAmiga Output/CLOSE/WAIT/SCREEN'||scrname
  58. Call Pragma '*','STDOUT'
  59. Call Open 'STDIN','*'
  60.  
  61. Call checkf
  62. pgpt = result
  63. If pgpt > 0  Then
  64. Do
  65.         cmd = cmdf
  66.         cmdline = ''
  67. End
  68. Else
  69. Do
  70.         Call ask
  71.         cmd = cmdn
  72.         cmdline = tempfile||' +batchmode=on'
  73. End
  74.  
  75.  
  76. Address Command
  77. 'GetEnv >PIPE:PGPUSER PGPUSER'
  78. If rc == 0 Then
  79. Do
  80.         If Open('user','PIPE:PGPUSER','R') Then
  81.         Do
  82.                 userid = ReadLN('user')
  83.                 If ~Close('user') Then Nop
  84.                 cmdline = cmdline||' -u '||'"'||userid||'"'
  85.         End
  86.         Else
  87.         Do
  88.                 Address porname
  89.                 Okay1 "Problem while opening PGPUSER environmental variable"||lf||,
  90.                 "Fatal error, macro execution aborted."
  91.                 Call quit
  92.         End
  93. End
  94.  
  95. address value portname
  96. cmdline = cmd||cmdline
  97. okay2 "Do you want the text you sign to be readable"||lf,
  98.         ||"after signing ( +clearsig=on ) ?"
  99. If result = 1 Then cmdline = cmdline||' +clearsig=on'
  100. If pgpt = 1 Then /* is PGP26_IMPERSONATE option avaliable ? */
  101. Do
  102.         okay2 "Do you want the encrypted packet to be"||lf,
  103.                 "in PGP 2.6 format ?"
  104.         If result = 1 Then
  105.         Do
  106.                 okay1 "WARNING: Packet created with this"||lf,
  107.                 ||"option set cannot be processed"||lf,
  108.                 ||"using 'standard' PGP 2.3a."||lf||lf,
  109.                 ||"You SHOULD NOT use this option"
  110.                 okay2 "Are you sure you want to use"||lf,
  111.                         ||"this option ?"
  112.                 If result = 1 Then cmdline = cmdline||' +PGP26_IMPERSONATE=on'
  113.         End
  114. End
  115. cut block
  116. If result = 1 Then Call sign
  117. Else
  118. Do
  119.         okay2 "No area selected."||lf||"Sign whole file ?"
  120.         If result = 1 Then
  121.         Do
  122.                 'beg of file'
  123.                 'mark block'
  124.                 'end of file'
  125.                 'cut block'
  126.                 Call sign
  127.         End
  128. End
  129. Call quit
  130.  
  131. sign:
  132. menu 0 6 0 tempfile      /* save block to file */
  133. Address Command
  134. 'PGP '||cmdline
  135. If rc == 0 Then
  136. Do
  137.         If Exists(tempfile||'.asc') Then
  138.         Do
  139.                 If Open('outf',tempfile||'.asc','R') Then
  140.                 Do /* we check if the file has length 0 what happens if PGP in -f mode encountered wrong password */
  141.                         If Seek('outf',100,'Begin') = 0 Then Call wrongpass
  142.                         Else
  143.                         Do
  144.                                 address value portname
  145.                                 include file tempfile||'.asc'
  146.                                 status 21
  147.                         End
  148.                 End
  149.         End
  150.         Else Call wrongpass
  151. End
  152. Else Call wrongpass
  153. Return
  154.  
  155. wrongpass:
  156. address value portname
  157. undo
  158. okay1 "Wrong passphrase !"
  159.  
  160. quit:
  161. Address Command
  162. If Exists(tempfile||'.info') Then 'Delete '||tempfile||'.info QUIET'
  163. If Exists(tempfile||'.asc') Then 'Delete '||tempfile||'.asc QUIET'
  164. If Exists(tempfile) Then 'Delete '||tempfile||' QUIET'
  165. If scratch == 1 Then 'Delete env:PGPPASS QUIET'
  166. If Close('STDOUT') Then Nop
  167. Exit 0
  168.  
  169. ask: Procedure Expose scratch lf portname
  170. Address Command
  171. 'GetEnv >NIL: PGPPASS'
  172. If rc ~= 0 Then
  173. Do
  174.         address value portname
  175.         okay2 "Your passphrase is not set in PGPPASS variable."||lf||,
  176.         "It must be set temporarily for running PGP".||lf||,
  177.         "Should it be deleted (for higher security) after use ??"
  178.         If result = 1 then scratch = 1
  179.         else scratch = 0
  180.         okay1 'WARNING: Your passphrase will be visible when you type it in.'
  181.         getstring "'  '  'Please enter passphrase.'"
  182.         pgppass = result
  183.         pgppass = Strip(pgppass,'T')
  184.         Address Command
  185.         'SetEnv PGPPASS '||'"'||pgppass||'"'
  186. End
  187. Return
  188.  
  189. checkf: Procedure
  190. Address Command
  191. Call getpath
  192. path = result
  193. If path = "" Then Return 0
  194. Else
  195. Do
  196.         'Version >PIPE:PGPVERSION '||path
  197.         If Open('pvers','PIPE:PGPVERSION','R') Then
  198.         Do
  199.                 verstring = ReadLN('pvers')
  200.                 If Close('pvers') Then Nop
  201.         End
  202.         Parse Var verstring . version
  203.         Select
  204.                 When version = '2.6ui' Then Return 2
  205.                 When version = '2.3a.5' Then Return 1
  206.                 When version = '2.3a.4' Then Return 1
  207.                 When version = '2.3a.3' Then Return 1
  208.                 Otherwise Return 0
  209.         End
  210. End
  211.  
  212. getpath: procedure
  213. 'Which >PIPE:PGPPATH PGP'
  214. If rc = 0 Then
  215. Do
  216.         If Open('ppath','PIPE:PGPPATH','R') Then
  217.         Do
  218.                 path = ReadLN('ppath')
  219.                 If ~Close('ppath') Then Nop
  220.                 Return path
  221.         End
  222. End
  223. Else
  224. Do
  225.         'GetEnv >PIPE:PGPPATH PGPPATH'
  226.         If rc = 0 Then
  227.         Do
  228.                 If Open('ppath','PIPE:PGPPATH','R') Then
  229.                 Do
  230.                         path = ReadLN('ppath')
  231.                         If ~Close('ppath') Then Nop
  232.                         path = path||'/PGP'
  233.                         Return path
  234.                 End
  235.                 Else Return ""
  236.         End
  237. End
  238.